package com.cpx.controller;

import com.cpx.dto.PageBeanDto;
import com.cpx.feign.TestFeign;
import com.cpx.vo.JsonResultVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Auther: PanBin
 * @Date: 2018-9-11 10:46
 * @Description:
 * @Version: 1.0
 */
@Controller
public class TestController {

    private static Logger logger = LogManager.getLogger(TestController.class);

    @Autowired
    private TestFeign testFeign;

    /**
     * @Author: PanBin
     * @Description: 分页查询请配单
     * @CreateDate: 2018-9-4 10:26
     * @Param [replenishOrder, pageNum, pageSize]
     * @Return com.cpx.vo.JsonResultVo
     */
    @ApiOperation(value = "测试")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前的页码(Y)",required = true,paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "一页显示的数量(Y)",required = true,paramType = "query",dataType = "int")
    })
    @RequestMapping(value = "/test", method = RequestMethod.POST, produces = "application/json")
    public @ResponseBody JsonResultVo test(Integer pageNum, Integer pageSize) {
        JsonResultVo resultVo = new JsonResultVo();
        try {
            PageBeanDto<ReplenishOrder> pageBeanDto = testFeign.test(new ReplenishOrder(),pageNum, pageSize);
            resultVo.setObject(pageBeanDto);
        } catch (Exception e) {
            resultVo.setErrMsg("补货单查询失败，请稍后再试");
            logger.error("补货单查询失败:" + e.getMessage());
            e.printStackTrace();
        }
        return resultVo;
    }

    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(Model model) {

        return "index";
    }

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String hello(Model model) {
        model.addAttribute("userName","PanBin");
        return "hello";
    }
}
